package com.wangqinlei.cowims126.service.impl;
import com.wangqinlei.cowims126.mapper.FoodMapper;
import com.wangqinlei.cowims126.pojo.Food;
import com.wangqinlei.cowims126.service.FoodService;
import com.wangqinlei.cowims126.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Classname FoodServiceImpl
 * @Description None
 * @Date 2019/6/29 20:09
 * @Created by WDD
 */
@Service
public class FoodServiceImpl implements FoodService {

    @Autowired
    private FoodMapper foodMapper;

    @Override
    public PageBean<Food> queryPage(Map<String, Object> paramMap) {
        PageBean<Food> pageBean = new PageBean<>((Integer) paramMap.get("pageno"),(Integer) paramMap.get("pagesize"));

        Integer startIndex = pageBean.getStartIndex();
        paramMap.put("startIndex",startIndex);
        List<Food> datas = foodMapper.queryList(paramMap);
        pageBean.setDatas(datas);

        Integer totalsize = foodMapper.queryCount(paramMap);
        pageBean.setTotalsize(totalsize);
        return pageBean;
    }

    @Override
    public int addFood(Food food) {
        return foodMapper.addFood(food);
    }

    @Override
    public int editFood(Food food) {
        return foodMapper.editFood(food);
    }

    @Override
    public int deleteFood(List<Integer> ids) {
        return foodMapper.deleteFood(ids);
    }

    @Override
    public List<Food> getFoodById(List<Integer> ids) {
        return foodMapper.getFoodById(ids);
    }

    @Override
    public int findByName(String name) {
        return foodMapper.findByName(name);
    }

}
